package belf.migrate.engine.ddl.trigger;

import belf.migrate.api.common.DatabaseIdentifier;
import belf.migrate.api.model.QualifiersModel;
import belf.migrate.api.table.schema.Catalog;
import belf.migrate.engine.ddl.AbstractConvertFactory;
import belf.migrate.engine.ddl.BaseDDLConvert;
import belf.migrate.engine.ddl.trigger.mysql.MySql2DMTriggerConvert;
import belf.migrate.engine.ddl.trigger.mysql.MySql2KingbaseTriggerConvert;
import belf.migrate.engine.ddl.trigger.oracle.Oracle2DMTriggerConvert;
import belf.migrate.engine.ddl.trigger.oracle.Oracle2KingbaseTriggerConvert;

/**
 * 工厂类，用于创建不同的数据库之间的触发器DDL转换器
 */
public class TriggerConvertFactory extends AbstractConvertFactory {
    public BaseDDLConvert create(String schema, String objectName, String sql, Catalog sourceCatalog, Catalog sinkCatalog,
                                 QualifiersModel qualifiersModel) {
        String IDENTIFIER = sourceCatalog.name() + "-" + sinkCatalog.name();
        switch (IDENTIFIER) {
            case DatabaseIdentifier.MYSQL + "-" + DatabaseIdentifier.DAMENG:
                return new MySql2DMTriggerConvert(objectName, sql, sourceCatalog, sinkCatalog, schema, qualifiersModel);
            case DatabaseIdentifier.ORACLE + "-" + DatabaseIdentifier.DAMENG:
                return new Oracle2DMTriggerConvert(objectName, sql, sourceCatalog, sinkCatalog, schema, qualifiersModel);
            case DatabaseIdentifier.MYSQL + "-" + DatabaseIdentifier.KINGBASE:
                return new MySql2KingbaseTriggerConvert(objectName, sql, sourceCatalog, sinkCatalog, schema, qualifiersModel);
            case DatabaseIdentifier.ORACLE + "-" + DatabaseIdentifier.KINGBASE:
                return new Oracle2KingbaseTriggerConvert(objectName, sql, sourceCatalog, sinkCatalog, schema, qualifiersModel);
            default:
                return new BaseDDLConvert(objectName, sql, sourceCatalog, sinkCatalog, schema, qualifiersModel);
        }
    }
}
